/**
 * LayerRenender.js
 * Version: 2.0
 * Author: wyh,lmc
 *
 */
//根据缩放级别以及，style名称，获取Style
function getStylebyZoom(zoom, styName) {
    var lyrStyle;
    var levelStyle;
    for (var i = 0; i < AllStyles.length; i++) {

        if (AllStyles[i].styleName == styName ) {
            lyrStyle = AllStyles[i];
            break;
        }

    }
    if (lyrStyle == null) return;

    for (var j = lyrStyle.layerStyle.length - 1; j >= 0; j--) {
        if (zoom <= lyrStyle.layerStyle[j].level) {
            levelStyle = lyrStyle.layerStyle[j];
        }
    }

    return levelStyle;
}

function _setLayerStyle(mylayer,styleName){
    mylayer.setStyle(function (feature, resolution) {
        var m_ConfigStyle = getStylebyZoom(map.getView().getZoom(),styleName);
        var m_style;
        if(m_ConfigStyle.style!=null)
        {
            if(m_ConfigStyle.renderfield=="")//如果不分类显示
            {
                m_style=m_ConfigStyle.style;
            }
            else //分类显示
            {
                m_style=m_ConfigStyle.style[feature.get(m_ConfigStyle.renderfield)];
            }
            if(m_style!=null){
                m_style.getText().setText(feature.get(m_ConfigStyle.diplayfield));
            }
           
        }
        return m_style;
    });
}

var LayerRenderer = function () {
    this.RenderLayer = function (layer, styleName) {
        _setLayerStyle(layer,styleName);
    };
    //根据名称获取stylefunction
    this.GetStyleFunction=function(styleName){
         var styleFunction=function (feature, resolution) {
            var m_ConfigStyle = getStylebyZoom(map.getView().getZoom(),styleName);
            var m_style;
            if(m_ConfigStyle.style!=null)
            {
                if(m_ConfigStyle.renderfield=="")//如果不分类显示
                {
                    m_style=m_ConfigStyle.style;
                }
                else //分类显示
                {
                    m_style=m_ConfigStyle.style[feature.get(m_ConfigStyle.renderfield)];
                }
                if(m_style!=null){
                    m_style.getText().setText(feature.get(m_ConfigStyle.diplayfield));
                }
               
            }
            return m_style;
        };
        return styleFunction;
    };
}